<template>
  <a-modal
    title="用户列表"
    :width="1000"
    :visible="visible"
    :maskClosable='false'
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">

    <a-table
      ref="table"
      bordered
      size="middle"
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      @change='handleTableChange'></a-table>
  </a-modal>
</template>

<script>
import {getUserList} from '@/api/api'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {getAction} from "../../../api/manage";

export default {
  name: "SelectUserListModal",
  mixins: [JeecgListMixin],
  data() {
    return {
      title: "操作",
      visible: false,
      model: {},
      confirmLoading: false,
      url: {
        add: "/act/model/create",
        list: "/sys/user/list"
      },
      columns: [
        {
          title: '用户账号',
          align: "center",
          dataIndex: 'username',
          fixed: 'left',
          width: 200
        },
        {
          title: '用户真实姓名',
          align: "center",
          dataIndex: 'realname',
        },
        {
          title: '性别',
          align: "center",
          dataIndex: 'sex_dictText'
        },
        {
          title: '手机号码',
          align: "center",
          dataIndex: 'phone'
        },
        {
          title: '邮箱',
          align: "center",
          dataIndex: 'email'
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status_dictText'
        }
      ]
    }
  },
  methods: {
    open() {
      this.visible = true;
      this.loadData()
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams(); //查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
      }).finally(() => {
        this.loading = false
      })
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.selectedRowKeys = []
      this.selectedRows = []
      this.ipagination.current = 1
      this.ipagination.pageSize = 30
    },
    handleChange(info) {
      let file = info.file;
      if (file.response.success) {
        this.$message.success(file.response.message);
        this.$emit('ok');
        this.close()
      } else {
        this.$message.warn(file.response.message);
        this.close()
      }
    },
    handleCancel() {
      this.close()
    },
    handleSubmit() {
      if (this.selectedRowKeys.length < 1) {
        this.$message.warning('请至少选择一条数据!')
        return
      } else {
        this.$emit('ok', this.selectionRows);
        this.close()
      }
    },
  }
}
</script>

<style>

</style>
